/*
 * Background Flickr: Copyright (C) 2009  Craig McNicholas
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.ddw.app.bflickr.flickr.api.url;

import com.ddw.app.bflickr.flickr.api.utils.EmailAddress;
import com.ddw.app.bflickr.flickr.api.utils.Website;
import com.ddw.app.bflickr.logging.Log;
import com.ddw.app.bflickr.logging.LogFactory;

/**
 * Factory class for creating all flickr api urls. This class should be 
 * used over directly creating the objects themselves as it saves time.
 * @author craig
 *
 */
public abstract class FlickrApiURLFactory {
	
	/**
	 * Enumeration for the flickr api query method type
	 * @author craig
	 */
	public enum FlickrQueryMethod {
		FIND_BY_EMAIL,
		FIND_BY_URL,
		FIND_BY_USERNAME
	};
	
	/**
	 * Enumeration for the flickr api get photos method type
	 * @author craig
	 */
	public enum FlickrGetPhotosMethod {
		FROM_USER_ID
	};
	
	private static Log log = LogFactory.createInstance(FlickrApiURLFactory.class);
	
	/**
	 * Factory method to create a flickr url for searching for a flickr accounts NSID from 
	 * the online REST api services.
	 * @param method the api REST method to use, the service to call.
	 * @param apiKey the api key to pass with the url so that flickr can validate the request
	 * @param query the query to send to the searching url service, if the method is to find an 
	 * email this string must be a valid email address, similarly if the request is to search for a 
	 * flickr users url then the url must be valid
	 * @return a FlickrURL object containing the properties for generating the REST api call.
	 * @throws AssertionError when the requested method has not been completed
	 * @throws IllegalArgumentException when the search query is in an incorrect format, 
	 * <i>this can happen if a search is made for a url or email and the query is in the incorrect format</i>
	 */
	public static FlickrFindURL createQueryURL(FlickrQueryMethod method, String apiKey, String query) throws AssertionError, IllegalArgumentException {
		switch(method) {
		case FIND_BY_EMAIL:
			log.debug("Creating FlickrFindByEmailURL.");
			return new FlickrFindByEmailURL(apiKey, new EmailAddress(query));
		case FIND_BY_URL:
			log.debug("Creating FlickrFindByWebsiteURL.");
			return new FlickrFindByWebsiteURL(apiKey, new Website(query));
		case FIND_BY_USERNAME:
			log.debug("Creating FlickrFindByUsernameURL.");
			return new FlickrFindByUsernameURL(apiKey, query);
		default:
			log.error("Could not create flickr url, Unknown operation.");
			throw new AssertionError("Could not create flickr url, Unknown operation.");
		}
	}
	
	/**
	 * Factory method to create a flickr url for querying the online REST api for a list of a 
	 * flickr accounts photos.
	 * @param method the api REST method to use, the service to call.
	 * @param apiKey the api key to pass with the url so that flickr can validate the request
	 * @param NSID the NSID of the flickr account to send to the service so that a photo list 
	 * can be returned
	 * @return a FlickrURL object containing the properties for generating the REST api call.
	 * @throws AssertionError when the requested method has not been completed
	 * @throws IllegalArgumentException when the NSID is in an incorrect format, 
	 * <i>this can happen if the NSID is empty or null</i>
	 */
	public static FlickrPhotosURL createGetPhotosURL(FlickrGetPhotosMethod method, String apiKey, String NSID) throws AssertionError, IllegalArgumentException {
		switch(method) {
		case FROM_USER_ID:
			log.debug("Creating FlickrGetPublicPhotosURL.");
			return new FlickrGetPublicPhotosURL(apiKey, NSID);
		default:
			log.error("Could not create flickr url, Unknown operation.");
			throw new AssertionError("Could not create flickr url, Unknown operation.");
		}
	}
	
}
